package com.work.straighttalk.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.rockerhieu.emojicon.EmojiconEditText;
import com.rockerhieu.emojicon.EmojiconGridFragment;
import com.rockerhieu.emojicon.EmojiconsFragment;
import com.rockerhieu.emojicon.emoji.Emojicon;
import com.work.straighttalk.R;
import com.work.straighttalk.app.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 朱相卿 on 16/3/19.
 */
public class GroupBuilderActivity extends BaseActivity
        implements EmojiconGridFragment.OnEmojiconClickedListener
        , EmojiconsFragment.OnEmojiconBackspaceClickedListener {
    @Bind(R.id.top_bar_back)
    ImageView topBarBack;
    @Bind(R.id.btn_next_step)
    Button btnNextStep;
    @Bind(R.id.sd_avater_group)
    SimpleDraweeView sdAvaterGroup;
    @Bind(R.id.et_group_name)
    EmojiconEditText etGroupName;
    @Bind(R.id.imbtn_emoji)
    ImageButton imbtnEmoji;
    @Bind(R.id.emoji_frame)
    FrameLayout emojiFrame;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_group_builder);
        ButterKnife.bind(this);
        setEmojiconFragment(false);
    }

    @OnClick(R.id.imbtn_emoji)
    protected void emojiSwitch() {
        switch (emojiFrame.getVisibility()) {
            case View.VISIBLE:
                emojiFrame.setVisibility(View.INVISIBLE);
                break;
            case View.INVISIBLE:
                emojiFrame.setVisibility(View.VISIBLE);
                break;
            default:
                break;
        }
    }

    @OnClick(R.id.btn_next_step)
    protected void toMemberPickActivity() {
        if (TextUtils.isEmpty(etGroupName.getText())) {
            toast(getString(R.string.text_provide_group_name_and_icon));
            return;
        }

    }

    /**
     * 加载Emojifragment
     *
     * @param useSystemDefault
     */
    private void setEmojiconFragment(boolean useSystemDefault) {
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.emoji_frame, EmojiconsFragment.newInstance(useSystemDefault))
                .commit();
    }

    @Override
    public void onEmojiconBackspaceClicked(View v) {
        EmojiconsFragment.backspace(etGroupName);
    }

    @Override
    public void onEmojiconClicked(Emojicon emojicon) {
        EmojiconsFragment.input(etGroupName, emojicon);
    }
}
